<?

//Initiate Authenticate
SecurityRedirect ();

//initiate Vars 

if (GetParam("debturList","")=='vendor') {
	define("PRIMARY_KEY","kdvendor");
	$FileTemplate  = "ais_setup_vendorlist_list.html";
	$nama = "nama";
	$code = "kdvendor";
	$TableName = "tblvendor";
	$SQL = "SELECT * FROM `$TableName` ";
	
} elseif (GetParam("debturList","")=='staff') {
	define("PRIMARY_KEY","nik");	
	$FileTemplate  = "ais_setup_stafflist_list.html";
	$nama = "nama";
	$code = "nik";
	$TableName = "tblstaff";
	$SQL = "SELECT * FROM `$TableName` LEFT JOIN tbldept ON $TableName.kddept=tbldept.kddept";
	
} else {
	define("PRIMARY_KEY","kdcust");
	$FileTemplate  = "ais_setup_custlist_list.html";
	$nama = "nama";
	$code = "kodecustomer";	
	$TableName = "customer";
	$SQL = "SELECT * FROM `$TableName` ";

	$DBConnection  = new mydb(DB_USER, DB_PASSWORD, DB_NAME2, DB_HOST);	
	mysql_select_db(DB_NAME2,$DBMysql);
	
}

$KEY[]         = array("PRIMARY_KEY"=>PRIMARY_KEY);
$FileName      = "ais_setup_debturlist.php";

$PageSize      = 10 ;
$HTMLGridList  = "DebturGrid";

//************ FORM ACTION **************
	if (GetParam("Action","")=="Delete") {
		DeleteRecord ("txtCheck",$PageSize);
	}


//Initiate Database Table For Search;
$FNama = GetParam("custSearch","");
$FCode = GetParam("custCodeSearch","");
$debturField = GetParam("debturField","");
$debnamField = GetParam("debnamField","");
$debturList  = GetParam("debturList","");

$FormName = GetParam("FormName","");
//******* DATABASE FORM QUERY ***********
$SQLCount = "SELECT count(*) FROM `$TableName` ";

if ($FNama) 
	if (strlen($WHERE)) $WHERE .= " AND "." $nama like '".$FNama."%'";
	else $WHERE .= " $nama like '".$FNama."%'";	
if ($FCode) 
	if (strlen($WHERE)) $WHERE .= " AND "." $code like '".$FCode."%'";
	else $WHERE .= " $code like '".$FCode."%'";

	if (strlen($WHERE))	$WHERE = " WHERE ".$WHERE;
	else $WHERE = " WHERE 1";

$SQL = $SQL.$WHERE;
$SQLCount = $SQLCount.$WHERE;

//******* SHOW FORM CONTENT *********
$PageNum = 1;
$RecCnt = $DBConnection->dbc->get_var($SQLCount) ; 

if (GetParam("PageNum","")) $PageNum  = GetParam("PageNum","");

$TBS = new clsTinyButStrong ;
$TBS->LoadTemplate($MOD_TEMPLATE_DIR."/".$FileTemplate);
$TBS->MergeBlock("bln",$KEY);
$TBS->MergeBlock("blg",$DBMysql,$SQL,$PageSize,$PageNum,$RecCnt);
$TBS->MergeNavigationBar('nv',array('size'=>10,'pos'=>'centred'),$PageNum,$RecCnt,$PageSize) ; 
$TBS->Show();

?>
